package com.wanger.swa.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wanger.swc.model.Result;
import com.wanger.swa.domain.myEnum.TemplateDynamicFieldEnum;
import com.wanger.swa.dto.templateDynamicField.query.TemplateDynamicFieldQuery;
import com.wanger.swa.dto.templateDynamicField.req.TemplateDynamicFieldAddReq;
import com.wanger.swa.dto.templateDynamicField.req.TemplateDynamicFieldUpdateReq;
import com.wanger.swa.dto.templateDynamicField.resp.TemplateDynamicFieldResp;
import com.wanger.swa.service.ise.TemplateDynamicFieldService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author: wanger
 * @Date: 2024/9/15 12:52
 * @Description: 模板动态字段
 */
@RestController
@Api(tags = "模板动态字段")
@RequiredArgsConstructor
@RequestMapping("/templateDynamicField")
public class TemplateDynamicFieldController {

    private final TemplateDynamicFieldService templateDynamicFieldService;

    @ApiOperation("添加模板动态字段")
    @PostMapping("/addTemplateDynamicField")
    public Result<TemplateDynamicFieldResp> addTemplateDynamicField(@RequestBody TemplateDynamicFieldAddReq addDTO) {
        return Result.ok(templateDynamicFieldService.addTemplateDynamicField(addDTO));
    }

    @ApiOperation("修改模板动态字段")
    @PutMapping("/updateTemplateDynamicField")
    public Result<TemplateDynamicFieldResp> updateTemplateDynamicField(@RequestBody TemplateDynamicFieldUpdateReq updateDTO) {
        return Result.ok(templateDynamicFieldService.updateTemplateDynamicField(updateDTO));
    }

    @ApiOperation("模板动态字段详情")
    @GetMapping("/getOneTemplateDynamicField")
    public Result<TemplateDynamicFieldResp> getOneTemplateDynamicField(String id) {
        return Result.ok(templateDynamicFieldService.getOneTemplateDynamicField(id));
    }

    @ApiOperation("分页查询模板动态字段")
    @GetMapping("/pageTemplateDynamicField")
    public Result<IPage<TemplateDynamicFieldResp>> pageTemplateDynamicField(TemplateDynamicFieldQuery query) {
        return Result.ok(templateDynamicFieldService.pageTemplateDynamicField(query));
    }

    @ApiOperation("模板动态字段列表查询")
    @GetMapping("/listTemplateDynamicField")
    public Result<List<TemplateDynamicFieldResp>> listTemplateDynamicField(TemplateDynamicFieldQuery query) {
        return Result.ok(templateDynamicFieldService.listTemplateDynamicField(query));
    }

    @ApiOperation("删除模板动态字段")
    @DeleteMapping("/deleteTemplateDynamicField")
    public Result<Void> deleteTemplateDynamicField(String id) {
        templateDynamicFieldService.deleteTemplateDynamicField(id);
        return Result.ok();
    }

    @ApiOperation("模板动态字段枚举")
    @GetMapping("/getEnumTemplateDynamicField")
    public Result<Map<String, List<Map<String, String>>>> getEnumTemplateDynamicField() {
        return Result.ok(TemplateDynamicFieldEnum.getList());
    }
}
